/*
 * Command.h
 *
 *  Created on: 2012-12-27
 *      Author: yangentao@gmail.com
 */

#pragma once;
#include "../yet/net/BaseSocket.h"
#include "Packet.h"
#include "FtpContext.h"
#include "ITask.h"

namespace ftp {
using namespace yet;

class Task: public ITask {
	typedef ITask Super;
public:
	Task();
	Task(FtpContext* context);
	virtual ~Task();
public:
	void connect(string host, u_short port);
	void login(string username, string password, string account = "");
	void quit();
	void noop();
	void pwd();
	void cwd(string pathname);
	void syst(); //215 UNIX Type: L8
	void rename(string from, string to);
	void cdup();
	void type(string type); //A|E|I|L[N|T|C]   //TODO type AN;  type L8
	void abor();
	void dele(string pathname);
	void rmd(string pathname);
	void mkd(string pathname);
	//FEAT
	//211-Features:
	// MDTM
	// REST STREAM
	// SIZE
	// MLST type*;size*;modify*;
	// MLSD
	// UTF8
	// CLNT
	// MFMT
	//211 End
	void feat();

	//ABOR ACCT ALLO APPE CDUP CWD  DELE EPRT EPSV FEAT HELP LIST MDTM MKD
	//MODE NLST NOOP OPTS PASS PASV PORT PWD  QUIT REIN REST RETR RMD  RNFR
	//RNTO SITE SIZE SMNT STAT STOR STOU STRU SYST TYPE USER XCUP XCWD XMKD
	//XPWD XRMD
	void help(string s = "");
	void pasv();
	void list(string pathname = "");
	void nlst(string pathname = "");
public:
	void rest(string maker);
	void acct(string account);
	void smnt(string pathname);
	void rein();
	void port(string host, short port);
	void stru(string stru);
	void mode(string mode);
	void stor(string pathname);
	void stou();
	void appe(string pathname);
	void allo(string n, string n2 = "");

	void site(string s);

	void stat(string pathname = "");

public:
	bool execute();
private:
	bool processCommand(Packet* packet);
	void saveData(Packet* packet);
	void init();

public:
	int cmd;
	boost::shared_ptr<Packet> packet;
};

} /* namespace yet */
